/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package LinkImageBN;

import DataAccess.LinkImageDA;
import HouseBN.HouseService;
import entity.House;
import entity.LinkImage;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author Mr-Quick
 */
public class InsertimginDB {

    EntityManager em;

    public InsertimginDB() {
        String persistenceUnitName = "SweetHomePU";
        EntityManagerFactory factory = Persistence.createEntityManagerFactory(persistenceUnitName);
        em = factory.createEntityManager();
    }

    public void insertimg(List<entity.LinkImage> photo, String Idhouse) {
        //String id = findidaccount(account);
        HouseService houseSV = new HouseService();
        House h = houseSV.Gethousebyid(Idhouse);
        LinkImageDA LIDA = new LinkImageDA(em);
        em.getTransaction().begin();
        for (int i = 0; i < photo.size(); i++) {
            photo.get(i).setIdImage(h);
            LIDA.create(photo.get(i));
        }
        em.getTransaction().commit();
    }
}
